home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Now 11 / CD-ROM Now MegaDisc 11 (1995-02).iso / discs / internet / unix4.txt < prev    next >
Text File  |  1994-10-26  |  28KB  |  657 lines

  1. Path: bloom-beacon.mit.edu!senator-bedfellow.mit.edu!faqserv
  2. From: tmatimar@isgtec.com (Ted Timar)
  3. Newsgroups: comp.unix.questions,comp.unix.shell,comp.answers,news.answers
  4. Subject: Unix - Frequently Asked Questions (4/7) [Frequent posting]
  5. Supersedes: <unix-faq/faq/part4_779635319@rtfm.mit.edu>
  6. Followup-To: comp.unix.questions
  7. Date: 23 Sep 1994 19:34:34 GMT
  8. Organization: ISG Technologies, Inc
  9. Lines: 637
  10. Approved: news-answers-request@MIT.Edu
  11. Distribution: world
  12. Expires: 21 Oct 1994 19:25:02 GMT
  13. Message-ID: <unix-faq/faq/part4_780348302@rtfm.mit.edu>
  14. References: <unix-faq/faq/contents_780348302@rtfm.mit.edu>
  15. NNTP-Posting-Host: bloom-picayune.mit.edu
  16. X-Last-Updated: 1994/09/08
  17. Originator: faqserv@bloom-picayune.MIT.EDU
  18. Xref: bloom-beacon.mit.edu comp.unix.questions:32519 comp.unix.shell:13050 comp.answers:7426 news.answers:26210
  19.  
  20. Archive-name: unix-faq/faq/part4
  21. Version: $Id: part4,v 2.5 1994/04/28 19:25:03 tmatimar Exp tmatimar $
  22.  
  23. These seven articles contain the answers to some Frequently Asked
  24. Questions often seen in comp.unix.questions and comp.unix.shell.
  25. Please don't ask these questions again, they've been answered plenty
  26. of times already - and please don't flame someone just because they may
  27. not have read this particular posting.  Thank you.
  28.  
  29. This collection of documents is Copyright (c) 1994, Ted Timar, except
  30. Part 6, which is Copyright (c) 1994, Pierre Lewis and Ted Timar.
  31. All rights reserved.  Permission to distribute the collection is
  32. hereby granted providing that distribution is electronic, no money
  33. is involved, reasonable attempts are made to use the latest version
  34. and all credits and this copyright notice are maintained.
  35. Other requests for distribution will be considered.  All reasonable
  36. requests will be granted.
  37.  
  38. All information here has been contributed with good intentions, but
  39. none of it is guaranteed either by the contributors or myself to be
  40. accurate.  The users of this information take all responsibility for
  41. any damage that may occur.
  42.  
  43. Many FAQs, including this one, are available on the archive site
  44. rtfm.mit.edu in the directory pub/usenet/news.answers.
  45. The name under which a FAQ is archived appears in the "Archive-Name:"
  46. line at the top of the article.  This FAQ is archived as
  47. "unix-faq/faq/part[1-7]".
  48.  
  49. These articles are divided approximately as follows:
  50.  
  51.       1.*) General questions.
  52.       2.*) Relatively basic questions, likely to be asked by beginners.
  53.       3.*) Intermediate questions.
  54.       4.*) Advanced questions, likely to be asked by people who thought
  55.            they already knew all of the answers.
  56.       5.*) Questions pertaining to the various shells, and the differences.
  57.       6.*) An overview of Unix variants.
  58.       7.*) An comparison of configuration management systems (RCS, SCCS).
  59.  
  60. This article includes answers to:
  61.  
  62.       4.1)  How do I read characters from a terminal without requiring the user
  63.               to hit RETURN?
  64.       4.2)  How do I check to see if there are characters to be read without
  65.               actually reading?
  66.       4.3)  How do I find the name of an open file?
  67.       4.4)  How can an executing program determine its own pathname?
  68.       4.5)  How do I use popen() to open a process for reading AND writing?
  69.       4.6)  How do I sleep() in a C program for less than one second?
  70.       4.7)  How can I get setuid shell scripts to work?
  71.       4.8)  How can I find out which user or process has a file open or is using
  72.             a particular file system (so that I can unmount it?)
  73.       4.9)  How do I keep track of people who are fingering me?
  74.       4.10) Is it possible to reconnect a process to a terminal after it has
  75.             been disconnected, e.g. after starting a program in the background
  76.             and logging out?
  77.       4.11) Is it possible to "spy" on a terminal, displaying the output
  78.             that's appearing on it on another terminal?
  79.  
  80. If you're looking for the answer to, say, question 4.5, and want to skip
  81. everything else, you can search ahead for the regular expression "^4.5)".
  82.  
  83. While these are all legitimate questions, they seem to crop up in
  84. comp.unix.questions or comp.unix.shell on an annual basis, usually
  85. followed by plenty of replies (only some of which are correct) and then
  86. a period of griping about how the same questions keep coming up.  You
  87. may also like to read the monthly article "Answers to Frequently Asked
  88. Questions" in the newsgroup "news.announce.newusers", which will tell
  89. you what "UNIX" stands for.
  90.  
  91. With the variety of Unix systems in the world, it's hard to guarantee
  92. that these answers will work everywhere.  Read your local manual pages
  93. before trying anything suggested here.  If you have suggestions or
  94. corrections for any of these answers, please send them to to
  95. tmatimar@isgtec.com.
  96.  
  97. ----------------------------------------------------------------------
  98.  
  99. Subject: How do I read characters ... without requiring the user to hit RETURN?
  100. Date: Thu Mar 18 17:16:55 EST 1993
  101.  
  102. 4.1)  How do I read characters from a terminal without requiring the user
  103.       to hit RETURN?
  104.  
  105.       Check out cbreak mode in BSD, ~ICANON mode in SysV.
  106.  
  107.       If you don't want to tackle setting the terminal parameters
  108.       yourself (using the "ioctl(2)" system call) you can let the stty
  109.       program do the work - but this is slow and inefficient, and you
  110.       should change the code to do it right some time:
  111.  
  112.       #include <stdio.h>
  113.       main()
  114.       {
  115.             int c;
  116.  
  117.             printf("Hit any character to continue\n");
  118.             /*
  119.              * ioctl() would be better here; only lazy
  120.              * programmers do it this way:
  121.              */
  122.             system("/bin/stty cbreak");        /* or "stty raw" */
  123.             c = getchar();
  124.             system("/bin/stty -cbreak");
  125.             printf("Thank you for typing %c.\n", c);
  126.  
  127.             exit(0);
  128.       }
  129.  
  130.       Several people have sent me various more correct solutions to
  131.       this problem.  I'm sorry that I'm not including any of them here,
  132.       because they really are beyond the scope of this list.
  133.  
  134.       You might like to check out the documentation for the "curses"
  135.       library of portable screen functions.  Often if you're interested
  136.       in single-character I/O like this, you're also interested in
  137.       doing some sort of screen display control, and the curses library
  138.       provides various portable routines for both functions.
  139.  
  140. ------------------------------
  141.  
  142. Subject: How do I check to see if there are characters to be read ... ?
  143. Date: Thu Mar 18 17:16:55 EST 1993
  144.  
  145. 4.2)  How do I check to see if there are characters to be read without
  146.       actually reading?
  147.  
  148.       Certain versions of UNIX provide ways to check whether characters
  149.       are currently available to be read from a file descriptor.  In
  150.       BSD, you can use select(2).  You can also use the FIONREAD ioctl
  151.       (see tty(4)), which returns the number of characters waiting to
  152.       be read, but only works on terminals, pipes and sockets.  In
  153.       System V Release 3, you can use poll(2), but that only works on
  154.       streams.  In Xenix - and therefore Unix SysV r3.2 and later - the
  155.       rdchk() system call reports whether a read() call on a given file
  156.       descriptor will block.
  157.  
  158.       There is no way to check whether characters are available to be
  159.       read from a FILE pointer.  (You could poke around inside stdio
  160.       data structures to see if the input buffer is nonempty, but that
  161.       wouldn't work since you'd have no way of knowing what will happen
  162.       the next time you try to fill the buffer.)
  163.  
  164.       Sometimes people ask this question with the intention of writing
  165.             if (characters available from fd)
  166.                     read(fd, buf, sizeof buf);
  167.       in order to get the effect of a nonblocking read.  This is not
  168.       the best way to do this, because it is possible that characters
  169.       will be available when you test for availability, but will no
  170.       longer be available when you call read.  Instead, set the
  171.       O_NDELAY flag (which is also called FNDELAY under BSD) using the
  172.       F_SETFL option of fcntl(2).  Older systems (Version 7, 4.1 BSD)
  173.       don't have O_NDELAY; on these systems the closest you can get to
  174.       a nonblocking read is to use alarm(2) to time out the read.
  175.  
  176. ------------------------------
  177.  
  178. Subject: How do I find the name of an open file?
  179. Date: Thu Mar 18 17:16:55 EST 1993
  180.  
  181. 4.3)  How do I find the name of an open file?
  182.  
  183.       In general, this is too difficult.  The file descriptor may
  184.       be attached to a pipe or pty, in which case it has no name.
  185.       It may be attached to a file that has been removed.  It may
  186.       have multiple names, due to either hard or symbolic links.
  187.  
  188.       If you really need to do this, and be sure you think long
  189.       and hard about it and have decided that you have no choice,
  190.       you can use find with the -inum and possibly -xdev option,
  191.       or you can use ncheck, or you can recreate the functionality
  192.       of one of these within your program.  Just realize that
  193.       searching a 600 megabyte filesystem for a file that may not
  194.       even exist is going to take some time.
  195.  
  196. ------------------------------
  197.  
  198. Subject: How can an executing program determine its own pathname?
  199. Date: Thu Mar 18 17:16:55 EST 1993
  200.  
  201. 4.4)  How can an executing program determine its own pathname?
  202.  
  203.       Your program can look at argv[0]; if it begins with a "/", it is
  204.       probably the absolute pathname to your program, otherwise your
  205.       program can look at every directory named in the environment
  206.       variable PATH and try to find the first one that contains an
  207.       executable file whose name matches your program's argv[0] (which
  208.       by convention is the name of the file being executed).  By
  209.       concatenating that directory and the value of argv[0] you'd
  210.       probably have the right name.
  211.  
  212.       You can't really be sure though, since it is quite legal for one
  213.       program to exec() another with any value of argv[0] it desires.
  214.       It is merely a convention that new programs are exec'd with the
  215.       executable file name in argv[0].
  216.  
  217.       For instance, purely a hypothetical example:
  218.         
  219.         #include <stdio.h>
  220.         main()
  221.         {
  222.             execl("/usr/games/rogue", "vi Thesis", (char *)NULL);
  223.         }
  224.  
  225.       The executed program thinks its name (its argv[0] value) is
  226.       "vi Thesis".   (Certain other programs might also think that
  227.       the name of the program you're currently running is "vi Thesis",
  228.       but of course this is just a hypothetical example, don't
  229.       try it yourself :-)
  230.  
  231. ------------------------------
  232.  
  233. Subject: How do I use popen() to open a process for reading AND writing?
  234. Date: Thu Mar 18 17:16:55 EST 1993
  235.  
  236. 4.5)  How do I use popen() to open a process for reading AND writing?
  237.  
  238.       The problem with trying to pipe both input and output to an
  239.       arbitrary slave process is that deadlock can occur, if both
  240.       processes are waiting for not-yet-generated input at the same
  241.       time.  Deadlock can be avoided only by having BOTH sides follow a
  242.       strict deadlock-free protocol, but since that requires
  243.       cooperation from the processes it is inappropriate for a
  244.       popen()-like library function.
  245.  
  246.       The 'expect' distribution includes a library of functions that a
  247.       C programmer can call directly.  One of the functions does the
  248.       equivalent of a popen for both reading and writing.  It uses ptys
  249.       rather than pipes, and has no deadlock problem.  It's portable to
  250.       both BSD and SV.  See the next answer for more about 'expect'.
  251.  
  252. ------------------------------
  253.  
  254. Subject: How do I sleep() in a C program for less than one second?
  255. Date: Thu Mar 18 17:16:55 EST 1993
  256.  
  257. 4.6)  How do I sleep() in a C program for less than one second?
  258.  
  259.       The first thing you need to be aware of is that all you can
  260.       specify is a MINIMUM amount of delay; the actual delay will
  261.       depend on scheduling issues such as system load, and could be
  262.       arbitrarily large if you're unlucky.
  263.  
  264.       There is no standard library function that you can count on in
  265.       all environments for "napping" (the usual name for short
  266.       sleeps).  Some environments supply a "usleep(n)" function which
  267.       suspends execution for n microseconds.  If your environment
  268.       doesn't support usleep(), here are a couple of implementations
  269.       for BSD and System V environments.
  270.  
  271.       The following code is adapted from Doug Gwyn's System V emulation
  272.       support for 4BSD and exploits the 4BSD select() system call.
  273.       Doug originally called it 'nap()'; you probably want to call it
  274.       "usleep()";
  275.  
  276.       /*
  277.             usleep -- support routine for 4.2BSD system call emulations
  278.             last edit:  29-Oct-1984     D A Gwyn
  279.       */
  280.  
  281.       extern int        select();
  282.  
  283.       int
  284.       usleep( usec )                            /* returns 0 if ok, else -1 */
  285.             long                usec;           /* delay in microseconds */
  286.             {
  287.             static struct                       /* `timeval' */
  288.                     {
  289.                     long        tv_sec;         /* seconds */
  290.                     long        tv_usec;        /* microsecs */
  291.                     }   delay;          /* _select() timeout */
  292.  
  293.             delay.tv_sec = usec / 1000000L;
  294.             delay.tv_usec = usec % 1000000L;
  295.  
  296.             return select( 0, (long *)0, (long *)0, (long *)0, &delay );
  297.             }
  298.  
  299.       On System V you might do it this way:
  300.  
  301.       /*
  302.       subseconds sleeps for System V - or anything that has poll()
  303.       Don Libes, 4/1/1991
  304.  
  305.       The BSD analog to this function is defined in terms of
  306.       microseconds while poll() is defined in terms of milliseconds.
  307.       For compatibility, this function provides accuracy "over the long
  308.       run" by truncating actual requests to milliseconds and
  309.       accumulating microseconds across calls with the idea that you are
  310.       probably calling it in a tight loop, and that over the long run,
  311.       the error will even out.
  312.  
  313.       If you aren't calling it in a tight loop, then you almost
  314.       certainly aren't making microsecond-resolution requests anyway,
  315.       in which case you don't care about microseconds.  And if you did,
  316.       you wouldn't be using UNIX anyway because random system
  317.       indigestion (i.e., scheduling) can make mincemeat out of any
  318.       timing code.
  319.  
  320.       Returns 0 if successful timeout, -1 if unsuccessful.
  321.  
  322.       */
  323.  
  324.       #include <poll.h>
  325.  
  326.       int
  327.       usleep(usec)
  328.       unsigned int usec;                /* microseconds */
  329.       {
  330.             static subtotal = 0;        /* microseconds */
  331.             int msec;                   /* milliseconds */
  332.  
  333.             /* 'foo' is only here because some versions of 5.3 have
  334.              * a bug where the first argument to poll() is checked
  335.              * for a valid memory address even if the second argument is 0.
  336.              */
  337.             struct pollfd foo;
  338.  
  339.             subtotal += usec;
  340.             /* if less then 1 msec request, do nothing but remember it */
  341.             if (subtotal < 1000) return(0);
  342.             msec = subtotal/1000;
  343.             subtotal = subtotal%1000;
  344.             return poll(&foo,(unsigned long)0,msec);
  345.       }
  346.  
  347.       Another possibility for nap()ing on System V, and probably other
  348.       non-BSD Unices is Jon Zeeff's s5nap package, posted to
  349.       comp.sources.misc, volume 4.  It does require a installing a
  350.       device driver, but works flawlessly once installed.  (Its
  351.       resolution is limited to the kernel HZ value, since it uses the
  352.       kernel delay() routine.)
  353.  
  354. ------------------------------
  355.  
  356. Subject: How can I get setuid shell scripts to work?
  357. Date: Thu Mar 18 17:16:55 EST 1993
  358.  
  359. 4.7)  How can I get setuid shell scripts to work?
  360.  
  361.       [ This is a long answer, but it's a complicated and frequently-asked
  362.         question.  Thanks to Maarten Litmaath for this answer, and
  363.         for the "indir" program mentioned below. ]
  364.  
  365.       Let us first assume you are on a UNIX variant (e.g. 4.3BSD or
  366.       SunOS) that knows about so-called `executable shell scripts'.
  367.       Such a script must start with a line like:
  368.  
  369.         #!/bin/sh
  370.  
  371.       The script is called `executable' because just like a real (binary)
  372.       executable it starts with a so-called `magic number' indicating
  373.       the type of the executable.  In our case this number is `#!' and
  374.       the OS takes the rest of the first line as the interpreter for
  375.       the script, possibly followed by 1 initial option like:
  376.  
  377.         #!/bin/sed -f
  378.  
  379.       Suppose this script is called `foo' and is found in /bin,
  380.       then if you type:
  381.  
  382.         foo arg1 arg2 arg3
  383.  
  384.       the OS will rearrange things as though you had typed:
  385.  
  386.         /bin/sed -f /bin/foo arg1 arg2 arg3
  387.  
  388.       There is one difference though: if the setuid permission bit for
  389.       `foo' is set, it will be honored in the first form of the
  390.       command; if you really type the second form, the OS will honor
  391.       the permission bits of /bin/sed, which is not setuid, of course.
  392.  
  393.       ----------
  394.  
  395.       OK, but what if my shell script does NOT start with such a `#!'
  396.       line or my OS does not know about it?
  397.  
  398.       Well, if the shell (or anybody else) tries to execute it, the OS
  399.       will return an error indication, as the file does not start with
  400.       a valid magic number.  Upon receiving this indication the shell
  401.       ASSUMES the file to be a shell script and gives it another try:
  402.  
  403.         /bin/sh shell_script arguments
  404.  
  405.       But we have already seen that a setuid bit on `shell_script' will
  406.       NOT be honored in this case!
  407.  
  408.       ----------
  409.  
  410.       Right, but what about the security risks of setuid shell scripts?
  411.  
  412.       Well, suppose the script is called `/etc/setuid_script', starting
  413.       with:
  414.  
  415.         #!/bin/sh
  416.         
  417.       Now let us see what happens if we issue the following commands:
  418.  
  419.         $ cd /tmp
  420.         $ ln /etc/setuid_script -i
  421.         $ PATH=.
  422.         $ -i
  423.  
  424.       We know the last command will be rearranged to:
  425.  
  426.         /bin/sh -i
  427.  
  428.       But this command will give us an interactive shell, setuid to the
  429.       owner of the script!
  430.       Fortunately this security hole can easily be closed by making the
  431.       first line:
  432.  
  433.         #!/bin/sh -
  434.  
  435.       The `-' signals the end of the option list: the next argument `-i'
  436.       will be taken as the name of the file to read commands from, just
  437.       like it should!
  438.  
  439.       ---------
  440.  
  441.       There are more serious problems though:
  442.  
  443.         $ cd /tmp
  444.         $ ln /etc/setuid_script temp
  445.         $ nice -20 temp &
  446.         $ mv my_script temp
  447.  
  448.       The third command will be rearranged to:
  449.  
  450.         nice -20 /bin/sh - temp
  451.  
  452.       As this command runs so slowly, the fourth command might be able
  453.       to replace the original `temp' with `my_script' BEFORE `temp' is
  454.       opened by the shell!  There are 4 ways to fix this security hole:
  455.  
  456.         1)  let the OS start setuid scripts in a different, secure way
  457.             - System V R4 and 4.4BSD use the /dev/fd driver to pass the
  458.             interpreter a file descriptor for the script
  459.  
  460.         2)  let the script be interpreted indirectly, through a frontend
  461.             that makes sure everything is all right before starting the
  462.             real interpreter - if you use the `indir' program from
  463.             comp.sources.unix the setuid script will look like this:
  464.  
  465.                 #!/bin/indir -u
  466.                 #?/bin/sh /etc/setuid_script
  467.  
  468.         3)  make a `binary wrapper': a real executable that is setuid and
  469.             whose only task is to execute the interpreter with the name of
  470.             the script as an argument
  471.  
  472.         4)  make a general `setuid script server' that tries to locate the
  473.             requested `service' in a database of valid scripts and upon
  474.             success will start the right interpreter with the right
  475.             arguments.
  476.  
  477.       ---------
  478.  
  479.       Now that we have made sure the right file gets interpreted, are
  480.       there any risks left?
  481.  
  482.       Certainly!  For shell scripts you must not forget to set the PATH
  483.       variable to a safe path explicitly.  Can you figure out why?
  484.       Also there is the IFS variable that might cause trouble if not
  485.       set properly.  Other environment variables might turn out to
  486.       compromise security as well, e.g. SHELL...  Furthermore you must
  487.       make sure the commands in the script do not allow interactive
  488.       shell escapes!  Then there is the umask which may have been set
  489.       to something strange...
  490.  
  491.       Etcetera.  You should realise that a setuid script `inherits' all
  492.       the bugs and security risks of the commands that it calls!
  493.  
  494.       All in all we get the impression setuid shell scripts are quite a
  495.       risky business!  You may be better off writing a C program instead!
  496.  
  497. ------------------------------
  498.  
  499. Subject: How can I find out which user or process has a file open ... ?
  500. Date: Thu Mar 18 17:16:55 EST 1993
  501.  
  502. 4.8)  How can I find out which user or process has a file open or is using
  503.       a particular file system (so that I can unmount it?)
  504.  
  505.       Use fuser (system V), fstat (BSD), ofiles (public domain) or
  506.       pff (public domain).  These programs will tell you various things
  507.       about processes using particular files.
  508.  
  509.       A port of the 4.3 BSD fstat to Dynix, SunOS and Ultrix
  510.       can be found in archives of comp.sources.unix, volume 18.
  511.  
  512.       pff is part of the kstuff package, and works on quite a few systems.
  513.       Instructions for obtaining kstuff are provided in question 3.10.
  514.  
  515. ------------------------------
  516.  
  517. Subject: How do I keep track of people who are fingering me?
  518. From: jik@rtfm.MIT.EDU (Jonathan I. Kamens)
  519. From: malenovi@plains.NoDak.edu (Nikola Malenovic)
  520. Date: Mon, 23 Nov 1992 16:01:45 -0600
  521.  
  522. 4.9)  How do I keep track of people who are fingering me?
  523.  
  524.       Generally, you can't find out the userid of someone who is
  525.       fingering you from a remote machine.  You may be able to
  526.       find out which machine the remote request is coming from.
  527.       One possibility, if your system supports it and assuming
  528.       the finger daemon doesn't object, is to make your .plan file a
  529.       "named pipe" instead of a plain file.  (Use 'mknod' to do this.)
  530.  
  531.       You can then start up a program that will open your .plan file
  532.       for writing; the open will block until some other process (namely
  533.       fingerd) opens the .plan for reading.  Now you can whatever you
  534.       want through this pipe, which lets you show different .plan
  535.       information every time someone fingers you.
  536.  
  537.       Of course, this may not work at all if your system doesn't
  538.       support named pipes or if your local fingerd insists
  539.       on having plain .plan files.
  540.  
  541.       Your program can also take the opportunity to look at the output
  542.       of "netstat" and spot where an incoming finger connection is
  543.       coming from, but this won't get you the remote user.
  544.  
  545.       Getting the remote userid would require that the remote site be
  546.       running an identity service such as RFC 931.  There are now three
  547.       RFC 931 implementations for popular BSD machines, and several
  548.       applications (such as the wuarchive ftpd) supporting the server.
  549.       For more information join the rfc931-users mailing list,
  550.       rfc931-users-request@kramden.acf.nyu.edu.
  551.  
  552.       There are three caveats relating to this answer.  The first is
  553.       that many NFS systems won't recognize the named pipe correctly.
  554.       This means that trying to read the pipe on another machine will
  555.       either block until it times out, or see it as a zero-length file,
  556.       and never print it.
  557.  
  558.       The second problem is that on many systems, fingerd checks that
  559.       the .plan file contains data (and is readable) before trying to
  560.       read it.  This will cause remote fingers to miss your .plan file
  561.       entirely.
  562.  
  563.       The third problem is that a system that supports named pipes
  564.       usually has a fixed number of named pipes available on the
  565.       system at any given time - check the kernel config file and
  566.       FIFOCNT option.  If the number of pipes on the system exceeds the
  567.       FIFOCNT value, the system blocks new pipes until somebody frees
  568.       the resources.  The reason for this is that buffers are allocated
  569.       in a non-paged memory.
  570.  
  571. ------------------------------
  572.  
  573. Subject: Is it possible to reconnect a process to a terminal ... ?
  574. Date: Thu Mar 18 17:16:55 EST 1993
  575.  
  576. 4.10) Is it possible to reconnect a process to a terminal after it has
  577.       been disconnected, e.g. after starting a program in the background
  578.       and logging out?
  579.  
  580.       Most variants of Unix do not support "detaching" and "attaching"
  581.       processes, as operating systems such as VMS and Multics support.
  582.       However, there are two freely redistributable packages which can
  583.       be used to start processes in such a way that they can be later
  584.       reattached to a terminal.
  585.  
  586.       The first is "screen," which is described in the
  587.       comp.sources.unix archives as "Screen, multiple windows on a CRT"
  588.       (see the "screen-3.2" package in comp.sources.misc, volume 28.)
  589.       This package will run on at least BSD, System V r3.2 and SCO UNIX.
  590.  
  591.       The second is "pty," which is described in the comp.sources.unix
  592.       archives as a package to "Run a program under a pty session" (see
  593.       "pty" in volume 23).  pty is designed for use under BSD-like
  594.       system only.
  595.  
  596.       Neither of these packages is retroactive, i.e. you must have
  597.       started a process under screen or pty in order to be able to
  598.       detach and reattach it.
  599.  
  600. ------------------------------
  601.  
  602. Subject: Is it possible to "spy" on a terminal ... ?
  603. Date: Thu Mar 18 17:16:55 EST 1993
  604.  
  605. 4.11) Is it possible to "spy" on a terminal, displaying the output
  606.       that's appearing on it on another terminal?
  607.  
  608.       There are a few different ways you can do this, although none
  609.       of them is perfect:
  610.  
  611.       * kibitz allows two (or more) people to interact with a shell
  612.         (or any arbitary program).  Uses include:
  613.  
  614.         - watching or aiding another person's terminal session;
  615.         - recording a conversation while retaining the ability to
  616.           scroll backwards, save the conversation, or even edit it
  617.           while in progress;
  618.         - teaming up on games, document editing, or other cooperative
  619.           tasks where each person has strengths and weakness that
  620.           complement one another.
  621.  
  622.         kibitz comes as part of the expect distribution.  See question 3.9.
  623.  
  624.         kibitz requires permission from the person to be spyed upon.  To
  625.         spy without permission requires less pleasant approaches:
  626.  
  627.       * You can write a program that rummages through Kernel structures
  628.         and watches the output buffer for the terminal in question,
  629.         displaying characters as they are output.  This, obviously, is
  630.         not something that should be attempted by anyone who does not
  631.         have experience working with the Unix kernel.  Furthermore,
  632.         whatever method you come up with will probably be quite
  633.         non-portable.
  634.  
  635.       * If you want to do this to a particular hard-wired terminal all
  636.         the time (e.g. if you want operators to be able to check the
  637.         console terminal of a machine from other machines), you can
  638.         actually splice a monitor into the cable for the terminal.  For
  639.         example, plug the monitor output into another machine's serial
  640.         port, and run a program on that port that stores its input
  641.         somewhere and then transmits it out *another* port, this one
  642.         really going to the physical terminal.  If you do this, you have
  643.         to make sure that any output from the terminal is transmitted
  644.         back over the wire, although if you splice only into the
  645.         computer->terminal wires, this isn't much of a problem.  This is
  646.         not something that should be attempted by anyone who is not very
  647.         familiar with terminal wiring and such.
  648.  
  649. ------------------------------
  650.  
  651. End of unix/faq Digest part 4 of 7
  652. **********************************
  653.  
  654. -- 
  655. Ted Timar - tmatimar@isgtec.com
  656. ISG Technologies Inc., 6509 Airport Road, Mississauga, Ontario, Canada L4V 1S7
  657.